from gensim.scripts.glove2word2vec import glove2word2vec
from gensim.models import KeyedVectors
word2vec_output_file = 'glove.6B.50d.word2vec.txt'  # 输出 Word2Vec 格式文件

model = KeyedVectors.load_word2vec_format(word2vec_output_file, binary=False)

# 查找与 "king" 最相似的词
similar_words = model.most_similar("king", topn=5)
print("Words similar to 'king':", similar_words)


# 计算 "king" 和 "queen" 的相似度
similarity = model.similarity("king", "queen")
print("Similarity between 'king' and 'queen':", similarity)

# 进行词语类比任务：king - man + woman = queen
result = model.most_similar(positive=["woman", "king"], negative=["man"], topn=1)
print("king - man + woman =", result[0][0])